/* 
 * File:   XbeeIf.h
 * Author: minaev
 *
 * Created on 25 Октябрь 2013 г., 8:46
 */

#ifndef XBEEIF_H
#define	XBEEIF_H

#include <queue>
#include <stdint.h>
#include <pthread.h>    

#include "Xcom.h"
#include "XTimeOut.h"
#include "Xpack.h"

#define ITR_WAIT_7E     0
#define ITR_READ_LEN    1
#define ITR_READ_PACK   2
#define ITR_READ_CRC    3
#define ITR_REG_MSG     4





class XbeeIf {
public:
    XbeeIf(Xcom* com);
    virtual ~XbeeIf();
    int waitByte();
    char* waitBuf(int len);
    int startScanThread();
    void write(Xpack* pck);
    Xpack* read();
private:
    Xcom* com;
    XTimeOut* tmWaitByte; //timeout of wait byte from COM
    std::queue<Xpack*> inputMsgs; //input messages
    //std::queue<uint16_t> inputMsgsLens; //input messages length
    int maxSize; //max size of inputMsgs
    int timeoutWB; //timeout wait one byte in COM
    
    int isLiveThreadScan; // 0 - thread scan is shutdown 1 - running
    int reqStopThread; //0 - not request for stop thread, 1 - request stop
    pthread_mutex_t mutexAccessMsgs; // access to inputMsgs and inputMsgsLens
    pthread_t thScan; //thread scan messages
    static void* threadScan(void* obj);
    
    
    void regMsg(const char* msg,int len);
};

#endif	/* XBEEIF_H */

